package 链表与双指针.m03.d11.t01;


import 链表与双指针.ListNode;

import java.util.HashSet;

public class Solution {
    public ListNode detectCycle(ListNode head) {
        HashSet<ListNode> LSet = new HashSet<>();
        ListNode cur = head;
        while(cur != null) {
            if(LSet.contains(cur)) {
                return cur;
            }
            LSet.add(cur);
            cur = cur.next;
        }
        return null;
    }
}